package pers.fish.sso.server.service.impl;

import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import pers.fish.sso.common.model.Authentication;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 写点什么吧
 *
 * @author HUAWEI
 * @date 2020/8/18
 */
@Component
public class MyLoginServiceImpl extends DefaultLoginServiceImpl{

    @Override
    protected Authentication doLogin(String username) {
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletRequestAttributes.getRequest();
        String password = request.getParameter("password");
        if("123456".equals(password) && "hello".equals(username)){
            Map<String,Object> user = new HashMap<>();
            user.put("id","123");
            user.put("nickname","张三");
            //校验用户名密码正确性 生成ticket
            Authentication authentication = new Authentication(user);
            return authentication;
        }

        return null;

    }
}
